package STUDENT.TRANDAODAIVI.THUVIEN.MODELS;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import STUDENT.TRANDAODAIVI.THUVIEN.IDENTITY.BookManager;
class bookborrowedtype{
	private String name;
	private int ammount;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAmmount() {
		return ammount;
	}
	public void setAmmount(int ammount) {
		this.ammount = ammount;
	}
	
}
public class Models3 {
public ArrayList<BookManager> management=new ArrayList<BookManager>();
	
	public void addBorrower(BookManager bookmanager){
		management.add(bookmanager);
	}
	public void showBorrower(){
		System.out.println("Tinh hinh sach muon hien tai trong thu vien: ");
		System.out.println("");
		for(BookManager bookmanager: management){
			System.out.println("Ten nguoi muon: "+bookmanager.getUserid());
			System.out.println("ID sach       : "+bookmanager.getBookid());
			System.out.println("Ten sach      : "+bookmanager.getBookname());

		}
	}
	public int checkDuplicatedIdBook(int id){
		for(BookManager bookmanager: management){
			if(bookmanager.getBookid()==id){
				return -1;
			}
		}
		return 1;
	}
	public void rankBook(){
		System.out.println("Danh sach sau khi duoc sap xep: ");
		List<bookborrowedtype> danhsach=new ArrayList<bookborrowedtype>();
		bookborrowedtype x;
		for (int i=0;i<management.size();i++){
			x=new bookborrowedtype();
			x.setName(management.get(i).getBookname());
			int zh=0;
			if(i>0){
			labelAll:for (int j=0;j<danhsach.size();j++){
				if(x.getName().equals(danhsach.get(j).getName())){
					zh=1;
					break labelAll;
				}else{
					zh=0;
				}
			}
			}
			if(zh==0){danhsach.add(x);};
		}

		for(int i=0;i<danhsach.size();i++){
			for(int j=0;j<management.size();j++){
				if(management.get(j).getBookname().equals(danhsach.get(i).getName())){
					danhsach.get(i).setAmmount(danhsach.get(i).getAmmount()+1);
				}
			}
		}
		for (int i=0;i<danhsach.size();i++){
			for(int j=i+1;j<danhsach.size();j++){
				if(danhsach.get(i).getAmmount()<danhsach.get(j).getAmmount()){
					bookborrowedtype a=new bookborrowedtype();
					a=danhsach.get(i);
					danhsach.set(i,danhsach.get(j));
					danhsach.set(j, a);
				}
			}
		}
		for(int i=0;i<danhsach.size();i++){
			System.out.println("Sach: "+danhsach.get(i).getName());
			System.out.println("Co  : "+danhsach.get(i).getAmmount()+" nguoi muon");
			System.out.println("");
		}
		
}
}